package com.jinsi.controller;

import com.jinsi.pojo.*;
import com.jinsi.service.ScTuitionApiServer;
import com.jinsi.service.impl.NewFeeServiceImpl;
import com.jinsi.service.impl.StuOperationLogServiceImpl;
import com.jinsi.utils.MapReturn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
public class NewFeeController {
    @Autowired
    private NewFeeServiceImpl service;
    @Autowired
    private StuOperationLogServiceImpl logServer;
    @Autowired
    private ScTuitionApiServer scTuitionApiServer;


    /**
     *
     * @param id
     * @return Map
     * 通过班级id查询学费
     */
    @ResponseBody
    @RequestMapping("/getClassById")
    public Map<String,Object> getClassById(Integer id){
        Map<String,Object> map = new HashMap<>();
        ScClasses classes = service.getClassById(id);
        map.put("data",classes);
        return map;
    }


    /**
     *
     * @param name
     * @return Map
     * 通过市场部名称查询市场部id
     */
    @ResponseBody
    @RequestMapping("/getMarketingByName")
    public Map<String,String> getMarketingByName(String name){
        Map<String,String> map = new HashMap<>();
        Integer marketId = service.getMarketingByName(name);
        map.put("id",marketId.toString());
        return map;
    }


    /**
     *
     * @param id
     * @param haveFees
     * @param documentWay
     * @return Map
     * 缴费
     */
    @ResponseBody
    @RequestMapping("/haveFee")
    public Map<String,Object> haveFee(int id, BigDecimal haveFees,int documentWay){
        return service.haveFee(id,haveFees,documentWay);
    }


    /**
     *
     * @param scStudent
     * @param standardId
     * @return Map
     * 添加学生信息
     */
    @ResponseBody
    @GetMapping("/stufee/addStudent")
    public Map<String,Object> addStudent(ScStudent scStudent,int standardId){
        //获取期数id
        try {
            scTuitionApiServer.iptStudentStandard(scStudent.getStudentId(),standardId);
            service.addScStudent(scStudent);
            ScStudentOperationLog log = new ScStudentOperationLog();
            log.setStudentId(scStudent.getStudentId());
            log.setStudentName(scStudent.getStudentName());
            log.setOperationDateTime(new Date());
            log.setOperationRemark("添加学生信息");
            log.setStatus(1);
            logServer.addLog(log);
            return MapReturn.getSuccess("存储成功");
        } catch (Exception e) {
            e.printStackTrace();
            return MapReturn.getError("存储失败");
        }
    }

}
